<?php

/**
 * Created on 7 mai 2011
 *  * @author Samy Deghou(deghou@polytech.unice.fr ; deghou@embl.de)
 * 		   Stephan Beisken (beisken@ebi.ac.uk)
 * 		   Luis Felipe De Figueiredo (ldpf@ebi.ac.uk)
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class NMRsignal implements iCRUD {
    /*
     * Attributes
     */

    private $_nmrSignalID;
    private $_intensity;
    private $_multiplicity;
    private $_comments;
    private $_spectrumID;

    /*
     * Constructor
     */

    public function NMRsignal($intensity, $multiplicity, $comments, $spectrumID, $nmrSignalID=-1) {
        $this->_intensity = $intensity;
        $this->_multiplicity = $multiplicity;
        $this->_comments = $comments;
        $this->_spectrumID = $spectrumID;
        $this->_nmrSignalID = $nmrSignalID;
    }

    /*
     * Accessors
     */

    public function getNmrSignalID() {
        return $this->_nmrSignalID;
    }

    public function getMultiplicity() {
        return $this->_multiplicity;
    }

    public function getIntensity() {
        return $this->_Intensity;
    }

    public function getComments() {
        return $this->_comments;
    }

    public function getSpectrumID() {
        return $this->_spectruumID;
    }

    /*
     * Modifiers
     */

    public function setNmrSignalID($param) {
        $this->_nmrSignalID = $param;
    }

    public function setMultiplicity($param) {
        $this->_multiplicity = $param;
    }

    public function setIntensity($param) {
        $this->_Intensity = $param;
    }

    public function setComments($param) {
        $this->_comments = $param;
    }

    public function setSpectrumID($param) {
        $this->_spectruumID = $param;
    }

    /*
     * CRUD
     */

    /**
     * Put an object in the database
     */
    public function create() {
        Database::connect();
        if ($this->_nmrSignalID != -1)
            die("Unable to create, still existing !");
        else {
            $query = "INSERT INTO `NMR_SIGNAL` values (NULL,'" .
                    $this->_intensity . "','" .
                    $this->_multiplicity . "','" .
                    $this->_comments . "','" .
                    $this->_spectrumID . "')";
            mysql_query($query) or die(mysql_error());
            $this->_idSujet = mysql_insert_id();
        }
        Database::disconnect();
    }

    /**
     * Read an object from the database
     */
    public static function read($key) {
        Database::connect();
        $query = "SELECT * FROM NMR_SIGNAL WHERE nmr_signal_id = '" . $key . "'";
        $ans = mysql_fetch_assoc(mysql_query($query));
        extract($ans);
        Database::disconnect();
        return new NMRsignal($intensity, $multiplicity, $comments, $spectrum_id, $nmrSignal_id);
        Database::disconnect();
    }

    /**
     * Update an object from the database
     */
    public function update() {
        Database::connect();
        $query = "UPDATE `NMR_SIGNAL` SET intensity='" .
                $this->_intensity . "', multiplicity='" .
                $this->_multiplicity . "', comments='" .
                $this->_comments . "', spectrum_id='" .
                $this->_spectrumID . "' WHERE nmr_signal_id='" .
                $this->_nmrSignalID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

    /**
     * Delete an object from the database
     */
    public function delete() {
        Database::connect();
        $query = "DELETE FROM `NMR_SIGNAL` WHERE nmr_signal_id='" .
                $this->_nmrSignalID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

}
?>
